package Test4;

import java.text.ParseException;
import java.util.Date;

public class Test4 {
    public static void main(String[] args) {
        System.out.println("=== DateUtils工具类测试 ===");

        // 测试Date转String
        System.out.println("\n1. 测试Date转String:");
        Date currentDate = new Date();
        String dateString = DateUtils.dateToString(currentDate);
        System.out.println("当前时间Date对象: " + currentDate);
        System.out.println("转换为字符串: " + dateString);

        // 测试String转Date
        System.out.println("\n2. 测试String转Date:");
        String testString = "2026-01-01 12:30:45";
        try {
            Date parsedDate = DateUtils.stringToDate(testString);
            System.out.println("原始字符串: " + testString);
            System.out.println("转换为Date对象: " + parsedDate);

            // 验证转换是否正确
            String backToString = DateUtils.dateToString(parsedDate);
            System.out.println("再次转换回字符串: " + backToString);
            System.out.println("转换是否一致: " + testString.equals(backToString));
        } catch (ParseException e) {
            System.err.println("日期解析错误: " + e.getMessage());
        }



    }
}
